{% extends 'base.html' %}
{% load humanize %}
{% block page-content %}
{% include 'nav_cat_bar.html' %}

<link href="/static/css/plugins/dataTables/dataTables.bootstrap.css" rel="stylesheet">
<link href="/static/css/plugins/dataTables/dataTables.responsive.css" rel="stylesheet">
<link href="/static/css/plugins/dataTables/dataTables.tableTools.min.css" rel="stylesheet">

<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-lg-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>主机初始化</h5>
                    <div class="ibox-tools">
                        <a class="collapse-link">
                            <i class="fa fa-chevron-up"></i>
                        </a>
                        <a class="dropdown-toggle" data-toggle="dropdown" href="#">
                            <i class="fa fa-wrench"></i>
                        </a>
                        <ul class="dropdown-menu dropdown-user">
                            <li><a href="#">Config option 1</a></li>
                            <li><a href="#">Config option 2</a></li>
                        </ul>
                        <a class="close-link">
                            <i class="fa fa-times"></i>
                        </a>
                    </div>
                </div>

                <div class="ibox-content">
                    <div class="row">
                    {% if error %}
                    <div class="alert alert-warning text-center">{{ error }}</div>
                    {% endif %}
                        <div class="col-sm-12 m-b-xs">
                              {% for num in pro_info %}
                                <a  class="btn btn-primary btn-write" href="?project={{num.mini_name}}"> {{num.name}}</a>
                              {% endfor %}
                        </div>
                    </div>
                    <div class="table-responsive">
                        <form id="contents_form" name="contents_form">
                            <table class="table table-striped table-bordered table-hover dataTables-example">
                            <thead>
                            <tr>
                                <th class="text-center">编号</th>
                                <th class="text-center">项目</th>
                                <th class="text-center">地区</th>
                                <th class="text-center">平台类型</th>
                                <th class="text-center">公网</th>
                                <th class="text-center">内网</th>
                                <th class="text-center">数据库</th>
                                <th class="text-center">初始端口</th>
                                <th class="text-center">用途</th>
                                <th class="text-center">备注</th>
                                <th class="text-center">是否初始化</th>
                            </tr>
                            </thead>

                            <tbody>
                            {% for num in host_info %}
                                <tr class="text-center">
                                    <td>
                                        {% ifequal num.host_init 1 %}
                                            {{forloop.counter}}
                                            <input type="checkbox" data-toggle="checkbox" name="nochoice"  value="{{num.p_ip}}" DISABLED>
                                        {% else %}
                                            {{forloop.counter}}
                                            <input type="checkbox" data-toggle="checkbox" name="choice_host"  value="{{num.p_ip}}" >
                                        {% endifequal %}
                                    </td>
                                    <td>{{num.project.mini_name}}</td>
                                    <td>{{num.area}}</td>
                                    <td>{{num.platform.mini_name}}</td>
                                    <td>{{num.p_ip}}</td>
                                    <td>{{num.s_ip}}</td>
                                    <td>{{num.db_ip}}</td>
                                    <td>{{num.port}}</td>
                                    <td>{% for use in num.use.all %} {{use}}{% endfor %}</td>
                                    <td>{{num.commit}}</td>
                                    {% ifequal num.host_init 1 %}
                                    <td><font color="green">已初始化</font></td>
                                    {% else %}
                                      <td><font color="red">未初始化</font></td>
                                    {% endifequal %}
                                </tr>
                            {% endfor %}
                            </tbody>
                        </table>

                        </div>

                        <input type="radio" data-toggle="radio"  name="checkradio" id="SelectAll" data-radiocheck-toggle="radio" onclick="choice(valu='all')" >全选
                        <input type="radio" data-toggle="radio" name="checkradio" id="SelectAll"  data-radiocheck-toggle="radio" onclick="choice(valu='no')">反选

                        <div class="hr-line-dashed"></div>
                        <div class="input-group col-xs-5 has-success">
                            <span class="input-group-addon">选择执行脚本</span>
                                <select class="form-control" name="script_name">
                                    <option>请选择脚本</option>
                                {% for num in script_list %}
                                    <option value="{{num.script_name}}">{{num.use_name}}-{{num.script_name}}</option>
                                {% endfor %}
                            </select>
                        </div>
                        </form>
                        <div class="hr-line-dashed"></div>

                        <button type="submit" class="btn btn-success dim" form="contents_form" formmethod="post" formaction="{% url 'init_hosts' %}?project={{project}}" name="switch" value="">开始初始化</button>
                        <button type="submit" class="btn btn-danger dim" form="contents_form" formmethod="post" formaction="{% url 'init_hosts' %}?project={{project}}&action=set_host_init" name="switch" value="">设置已初始化</button>
                    </div>
                </div>
            </div>
        </div>
</div>


<script src="/static/js/plugins/dataTables/jquery.dataTables.js"></script>
<script src="/static/js/plugins/dataTables/dataTables.bootstrap.js"></script>
<script src="/static/js/plugins/dataTables/dataTables.responsive.js"></script>
<script src="/static/js/plugins/dataTables/dataTables.tableTools.min.js"></script>

<script type="text/javascript">
$(document).ready(function() {
            $('.dataTables-example').dataTable({
                responsive: true,
                "dom": 'T<"clear">lfrtip',
                "tableTools": {
                    "aButtons":false,
                    //"sSwfPath": "/static/js/plugins/dataTables/swf/copy_csv_xls_pdf.swf"
                }
            });
        });
    function choice(valu){
                var ids=$("input[name='choice_host']");
                if (valu == "all"){
　　                    for(var i=0;i<ids.length;i++){
　　　　                        ids[i].checked="checked";
　　                    }
                }else if (valu == "no") {
　　                    for(var i=0;i<ids.length;i++){
　　　　                ids[i].checked="";
　　                    }
                }
        }
</script>


{% endblock %}
